package com.lanp.springredis.listener;

import com.lanp.springredis.scv.RedisCSV;
import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class TopicUserListener implements ApplicationRunner, Ordered {
    @Resource
    private RedissonClient redisson;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("开始监控topic_user消息");
        this.listener();
    }

    private void listener() {
        RTopic topic = redisson.getTopic(RedisCSV.topic_user.getKey());
        topic.addListener(String.class, (channel, msg) -> {
            System.out.println("topic_user接收到的信息：" + msg);
        });
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
